package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2019/1/7 09:45
 * @description
 */
public class Code12 {
    public static void main(String[] args) {
        new Code12().intToRoman(3);
    }
    private String[][] m = {
        {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"},
        {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"},
        {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"},
        {"", "M", "MM", "MMM"}
    };

    public String intToRoman(int num) {
        StringBuilder result = new StringBuilder();
        int length = (num + "").length();
        for (int i = 0; i < length; i++) {
            int r = num % 10;
            result.insert(0, m[i][r]);
            num /= 10;
        }
        return result.toString();
    }
}
